<template>
    <div class="filter">
        <div class="filter-item">
            <label for="">所属单位：</label>
            <el-select
                v-model="searchForm.depId"
                class="m-2"
                placeholder="请选择所属单位"
                style="width: 145px"
                :disabled="localTypeUnit != '1'"
            >
                <el-option
                    v-for="item in depIdList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                />
            </el-select>
        </div>

        <div class="filter-item">
            <label for="">计划名称：</label>
            <el-input
                v-model="searchForm.planName"
                placeholder="请输入计划名称"
                style="width: 145px"
            />
        </div>
        <div class="filter-item">
            <label for="">巡检级别：</label>
            <el-select
                v-model="searchForm.inspectionLevel"
                class="m-2"
                placeholder="请选择巡检级别"
                style="width: 145px"
            >
                <el-option
                    v-for="item in inspectionLevelList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                />
            </el-select>
        </div>
        <div class="filter-item">
            <label for="">任务状态：</label>
            <el-select
                v-model="searchForm.status"
                class="m-2"
                placeholder="请选择任务状态"
                style="width: 145px"
            >
                <el-option
                    v-for="item in statusList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                />
            </el-select>
        </div>
        <div class="filter-item">
            <label for="">计划日期：</label>
            <el-date-picker
                style="width: 260px"
                v-model="searchForm.dateTime"
                type="daterange"
                unlink-panels
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                :size="'default'"
                :shortcuts="shortcuts"
            />
        </div>
        <div class="filter-item">
            <el-button
                size="default"
                type="primary"
                @click="search"
            >查询</el-button>
            <el-button
                size="default"
                type="primary"
                @click="reset"
            >重置</el-button>
            <el-button
                size="default"
                type="success"
                @click="updateSearch"
            >更新任务</el-button>
        </div>
    </div>

    <el-table
        :data="tableData"
        style="width: 100%"
        id="inspectionTask"
    >
        <el-table-column
            type="index"
            label="序号"
            width="55"
        />
        <el-table-column
            prop="depName"
            label="所属单位"
        />
        <el-table-column
            prop="planName"
            label="计划名称"
            width="120"
        />
        <el-table-column
            prop="inspectionInterval"
            label="巡检周期"
        />
        <el-table-column
            prop="inspectionEquipmentName"
            label="巡检设备"
            width="160"
        />
        <el-table-column
            prop="inspItemList"
            label="查看项目"
            min-width="160"
        >
            <template #default="scope">
                <el-popover
                    trigger="hover"
                    placement="top"
                >
                    <template #reference>
                        <el-tag type="">项目</el-tag>
                    </template>

                    <div class="scopeBox">
                        <div class="dialogTitle">
                            <p>巡检项目</p>
                        </div>

                        <div
                            v-for="(item, index) in scope.row.inspItemList"
                            :key="item"
                        >
                            {{ index + 1 }}. {{ item }}
                        </div>
                    </div>
                </el-popover>
            </template>
        </el-table-column>
        <el-table-column
            prop="inspectionLevel"
            label="巡检级别"
        />
        <el-table-column
            prop="planInspDate"
            label="计划巡检日期"
            width="120"
        />
        <el-table-column
            prop="planInspUserName"
            label="计划巡检人员"
            width="120"
        />
        <el-table-column
            prop="status"
            label="任务状态"
        >
            <template #default="scope">
                {{
                    scope.row.status == "0"
                        ? "未开始"
                        : scope.row.status == "10"
                        ? "进行中"
                        : "已完成"
                }}
            </template>
        </el-table-column>
        <el-table-column
            prop="inspTime"
            label="巡检完成时间"
            width="120"
        />
        <el-table-column
            prop="inspUserName"
            label="巡检人员"
        />
        <el-table-column
            fixed="right"
            label="操作"
            width="190"
        >
            <template #default="scope">
                <el-button
                    text
                    type="primary"
                    size="small"
                    :disabled="
                        scope.row.inspUser != null && scope.row.status != 0
                    "
                    @click="optionAdjust(scope.row)"
                >
                    调整
                </el-button>
                <el-button
                    text
                    type="primary"
                    size="small"
                    style="margin-left: 0"
                    :disabled="!(scope.row.status == '10')"
                    @click="reportTask(scope.row)"
                >
                    填报
                </el-button>
                <el-button
                    text
                    type="primary"
                    size="small"
                    style="margin-left: 0"
                    @click="optionRecord(scope.row)"
                >
                    操作记录
                </el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-pagination
        v-model:current-page="searchForm.pageNo"
        v-model:page-size="searchForm.pageSize"
        layout="total, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        class="paginationStyle"
    />
    <el-dialog
        v-model="recordListVisible"
        title="操作记录"
        width="1000"
    >
        <div class="filter">
            <div class="filter-item">
                <label for="">操作时间：</label>
                <el-date-picker
                    style="width: 240px"
                    v-model="recordTime"
                    type="daterange"
                    unlink-panels
                    range-separator="至"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                    :size="'default'"
                    :shortcuts="shortcuts"
                />
            </div>
            <div class="filter-item">
                <el-button
                    size="default"
                    type="warning"
                    @click="searchRecord(currentRowRecord)"
                >查询</el-button>
            </div>
        </div>
        <el-table
            :data="recordList"
            style="width: 100%"
        >
            <el-table-column
                prop="operationType"
                label="操作类型"
            />
            <el-table-column
                prop="createTime"
                label="操作时间"
                width="160"
            />
            <el-table-column
                prop="comment"
                label="操作内容"
                width="560"
            />
            <el-table-column
                prop="operationRealname"
                label="操作人"
            />
        </el-table>
        <el-pagination
            v-model:current-page="recordPageNo"
            v-model:page-size="recordPageSize"
            layout="total, prev, pager, next, jumper"
            :total="totalRecord"
            @size-change="handleSizeChangeRecord"
            @current-change="handleCurrentChangeRecord"
            class="paginationStyle"
        />
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="recordListVisible = false">取消</el-button>
            </div>
        </template>
    </el-dialog>
    <el-dialog
        v-model="adjustVisible"
        title="调整"
        width="600"
    >
        <el-form label-width="120">
            <el-form-item
                label="调整项："
                prop="name"
            >
                <el-select
                    v-model="adjustType"
                    placeholder=""
                    style="width: 200px"
                >
                    <el-option
                        v-for="item in adjustList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item
                label="巡检人员："
                prop="name"
                style="width: 450px"
                v-show="adjustType == '巡检人员'"
            >
                <el-radio-group v-model="inspectionType">
                    <el-radio label="当日值班班组">当日值班班组</el-radio>
                    <el-radio label="固定班组">固定班组</el-radio>
                    <el-radio label="固定人员">固定人员</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item
                label=""
                prop="inspectionUser"
                v-show="adjustType == '巡检人员'"
            >
                <el-select
                    v-model="inspectionUser"
                    :placeholder="`请选择${inspectionType}`"
                    style="width: 200px"
                >
                    <el-option
                        :label="item.label"
                        :value="item.value"
                        v-for="item in typeList"
                        :key="item.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item
                label="计划巡检时间："
                prop="name"
                style="width: 450px"
                v-show="adjustType == '计划巡检时间'"
            >
                <el-date-picker
                    style="width: 200px"
                    v-model="adjustTime"
                    type="date"
                    :size="'default'"
                />
            </el-form-item>
            <el-form-item
                label="任务状态："
                prop="name"
                style="width: 450px"
                v-show="adjustType == '任务状态'"
            >
                <el-select
                    v-model="adjustStatus"
                    placeholder=""
                    style="width: 200px"
                >
                    <el-option
                        v-for="item in adjustStatusList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="adjustVisible = false">取消</el-button>
                <el-button
                    type="primary"
                    @click="adjusConfirm"
                >
                    确认
                </el-button>
            </div>
        </template>
    </el-dialog>
    <el-dialog
        v-model="reportTaskVisible"
        title="填报"
        width="700"
    >
        <el-tabs
            :tab-position="'left'"
            style="height: 300px"
            class="demo-tabs"
            v-model="activeName"
            :key="activeName"
            @tab-change="handleClick"
        >
            <el-tab-pane
                style="white-space: wrap"
                v-for="(item, index) in reportTaskDataList"
                :key="item.eqId"
                :name="item.id"
            >
                <template #label>
                    <div class="reportLabel">
                        <p>{{ item.facilityName }}</p>
                        <p>{{ item.facilityLocations }}</p>
                        <p>{{ item.facilityNumber }}</p>
                    </div>
                </template>
                <div class="projectBox">
                    <p>巡检项目</p>
                    <ul>
                        <li
                            v-for="(value, key) in item.items"
                            :key="key"
                        >
                            <div
                                class="liItem"
                                style="flex: 1"
                            >{{ key }}</div>
                            <div
                                class="liItem"
                                style="width: 130px"
                            >
                                <el-radio-group
                                    style="width: 100%"
                                    v-model="item.items[key]"
                                    @change="(val) => (item.items[key] = val)"
                                >
                                    <el-radio
                                        label="正常"
                                        size="small"
                                    >正常</el-radio>
                                    <el-radio
                                        label="异常"
                                        size="small"
                                    >异常</el-radio>
                                </el-radio-group>
                            </div>
                        </li>
                    </ul>
                    <div class="urlBox">
                        <p>
                            现场图片
                            <span style="font-size: 12px">(最多上传3张图片)</span>
                        </p>
                        <el-upload
                            v-model:file-list="item.fileUrlList"
                            action="#"
                            :http-request="
                                (file) => {
                                    httpRequest(file, index);
                                }
                            "
                            list-type="picture-card"
                            :on-remove="
                                (file) => {
                                    handleRemove(file, index);
                                }
                            "
                            :on-preview="handlePictureCardPreview"
                            accept=".png,.jpg"
                            :limit="3"
                        >
                            <el-icon>
                                <Plus />
                            </el-icon>
                        </el-upload>
                    </div>
                </div>
            </el-tab-pane>
        </el-tabs>
        <div style="padding: 15px">
            <el-input
                v-model="inspContent"
                :autosize="{ minRows: 2, maxRows: 4 }"
                type="textarea"
                placeholder="请输入巡检内容"
            />
        </div>
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="reportTaskVisible = false">取消</el-button>
                <el-button
                    type="warning"
                    @click="saveTaskConfirm"
                >
                    保存
                </el-button>
                <el-button
                    type="primary"
                    @click="reportTaskConfirm"
                >
                    提交
                </el-button>
            </div>
        </template>
    </el-dialog>

    <el-dialog
        v-model="updatePlanVisible"
        title="更新"
        width="400"
    >
        <div class="filter-item">
            <label for="">排班周期：</label>
            <el-date-picker
                style="width: 260px"
                v-model="updateTime"
                type="daterange"
                unlink-panels
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                :size="'default'"
                :shortcuts="shortcuts2"
                :disabled-date="disabledDate"
            />
        </div>
        <div style="line-height: 2; margin: 20px 0">
            <p>
                <el-icon
                    color="#e6a23c"
                    style="
                        font-size: 16px;
                        font-weight: 600;
                        vertical-align: middle;
                        margin: -2px 6px 0 0;
                    "
                    @click="popoverVisible = false"
                >
                    <Warning />
                </el-icon>是否确认更新？【注：从选择日期起，按最新巡检计划更新任务，已调整人员及时间将会被覆盖】
            </p>
        </div>
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="updatePlanVisible = false">取消</el-button>
                <el-button
                    type="primary"
                    @click="submitUpdatePlan()"
                >
                    确认
                </el-button>
            </div>
        </template>
    </el-dialog>
    <el-dialog
        v-model="dialogVisible"
        title="图片预览"
    >
        <img
            style="width: 100%"
            :src="dialogImageUrl"
            alt="Preview Image"
        />
    </el-dialog>
</template>

<script setup>
import schedulingHttp from "@/https/scheduling.js";
import userHttp from "@/https/user.js";
import Storage from "@/utils/storage.js"; // storage工具类，简单的封装
import { Plus, Warning } from "@element-plus/icons-vue";
import { ElMessage } from "element-plus";
import moment from "moment";
import { onMounted, reactive, ref, watch } from "vue";
const nowTime = new Date().getTime();
const day = new Date().getDay();
const oneDayTime = 24 * 60 * 60 * 1000;
const inspContent = ref("");
const currentUser = Storage.localGet("userId");
let searchForm = reactive({
    depId: "",
    inspectionLevel: "",
    planName: "",
    dateTime: [moment(), moment().add(7, "day")],
    status: "",
    pageNo: 1,
    pageSize: 10,
});
const depIdList = ref([
    { label: "全部", value: "1" },
    { label: "星沙厂", value: "2" },
    { label: "城西厂", value: "3" },
    { label: "城北厂", value: "4" },
    { label: "城南厂", value: "5" },
    { label: "城东厂", value: "6" },
]);
const inspectionLevelList = ref([
    { label: "全部", value: "" },
    { label: "一级", value: "一级" },
    { label: "二级", value: "二级" },
    { label: "三级", value: "三级" },
]);
const statusList = ref([
    { label: "全部", value: "" },
    { label: "未开始", value: "0" },
    { label: "进行中", value: "10" },
    { label: "已完成", value: "90" },
    { label: "已关闭", value: "100" },
]);
const localTypeUnit = ref(Storage.localGet("depId"));
searchForm.depId = localTypeUnit.value;

const recordListVisible = ref(false);
const adjustVisible = ref(false);

const shortcuts = [
    {
        text: "本年",
        value: () => {
            return [
                moment().startOf("year"),
                moment().endOf("year"),
            ];
        },
    },
    {
        text: "本月",
        value: () => {
            return [
                moment().startOf("month"),
                moment().endOf("month"),
            ];
        },
    },
    {
        text: "下月",
        value: () => {
            return [
                moment().add(1, 'month').startOf("month"),
                moment().add(1, 'month').endOf("month"),
            ];
        },
    },
    {
        text: "本周",
        value: () => {
            return [
                moment().startOf("week"),
                moment().endOf("week"),
            ];
        },
    },
    {
        text: "下周",
        value: () => {
            return [
                moment().add(1, 'week').startOf("week"),
                moment().add(1, 'week').endOf("week"),
            ];
        },
    },
    {
        text: "本日",
        value: () => {
            return [
                moment(),
                moment(),
            ];
        },
    },
];
const shortcuts2 = [
    {
        text: "仅本月",
        value: () => {
            const now = new Date();
            const end = new Date(now.getFullYear(), now.getMonth() + 1, 0);
            const start = moment(new Date()).add(1, "day");
            return [start, end];
        },
    },
    {
        text: "本月及以后",
        value: () => {
            const now = new Date();
            const end = new Date(now.getFullYear(), now.getMonth() + 2, 0);
            const start = moment(new Date()).add(1, "day");
            return [start, end];
        },
    },
];
const disabledDate = (time) => {
    // 禁用今天之前的日期
    return time.getTime() < Date.now(); // 8.64e7 毫秒数代表一天
};
const updateTime = ref([
    // "2024-04-01",
    // "2024-04-30",
    moment(new Date()),
    new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0),
]);
let ruleForm = reactive({
    region: "",
    name: "",
    desc: "",
    continuous: "",
    value1: [],
    type11: "class",
    number: 1,
    dayNumber: 1,
    monthNumber: 1,
    weekNumber: "1",
    week: "Mon",
    inspectionType: 1,
});
const tableData = ref([]);
const adjustType = ref("巡检人员");
const inspectionType = ref("当日值班班组");
const inspectionUser = ref("");
const typeList = ref([]);
const adjustTime = ref(moment().format("YYYY-MM-DD"));
const adjustStatus = ref("100");

const classesShowList = ref([]);
// 查询班次信息
const getWorkClassQueryWorkClassShow = async (row) => {
    let params = {
        depId: row.depId,
        classType: "1",
        isDelete: "0",
        pageNo: 1,
        pageSize: 1000,
    };
    const res = await schedulingHttp.workClassQueryWorkClass(params);
    if (res.data.code == 200) {
        res.data.data.records.forEach((item) => {
            item.label = item.className;
            item.shortLabel = item.classShortName + "";
            item.value = item.id + "";
            item.statusTrigger = false;
        });
        classesShowList.value = res.data.data.records;
        typeList.value = classesShowList.value;
    }
};
const userList = ref([]);
const userQueryUserList = async (row) => {
    let params = {
        depId: row.depId,
        isDelete: 0,
        pageNo: 1,
        pageSize: 10000,
    };
    const res = await userHttp.userQueryUserList(params);
    if (res.data.code == 200) {
        res.data.data.records.forEach((item) => {
            item.label = item.realName;
            item.value = item.id + "";
        });
        userList.value = res.data.data.records;
    }
};
const groupList = ref([]);
// 查询班组信息
const getWorkteamsQueryWorkTeams = async (row) => {
    let params = {
        depId: row.depId,
        pageNo: 1,
        pageSize: 10000,
    };
    const res = await schedulingHttp.workteamsQueryWorkTeams(params);
    if (res.data.code == 200) {
        res.data.data.records.forEach((item) => {
            item.label = item.teamName;
            item.value = item.id;
        });
        groupList.value = res.data.data.records;
    }
};
watch(
    inspectionType,
    (val) => {
        if (val == "当日值班班组") {
            typeList.value = classesShowList.value;
        } else if (val == "固定班组") {
            typeList.value = groupList.value;
        } else if (val == "固定人员") {
            typeList.value = userList.value;
        }
    },
    { deep: true }
);
const adjustStatusList = ref([
    { label: "未开始", value: "0" },
    { label: "进行中", value: "10" },
    { label: "已完成", value: "100" },
]);
const adjustList = ref([
    { label: "巡检人员", value: "巡检人员" },
    { label: "计划巡检时间", value: "计划巡检时间" },
    { label: "任务状态", value: "任务状态" },
]);
const currentAdjustRow = ref();
const optionAdjust = (row) => {
    getWorkClassQueryWorkClassShow(row);
    getWorkteamsQueryWorkTeams(row);
    userQueryUserList(row);
    adjustVisible.value = true;
    adjustType.value = "巡检人员";
    inspectionType.value = "当日值班班组";
    adjustTime.value = moment().format("YYYY-MM-DD");
    adjustStatus.value = "100";
    currentAdjustRow.value = row;
};
const adjusConfirm = async () => {
    let params = {
        id: "",
        inspPlanDate: "",
        operateUser: "",
        status: "",
        userMode: "",
    };
    params.id = currentAdjustRow.value.id;
    if (adjustType.value == "巡检人员") {
        params.inspPlanDate = "";
        params.status = "";
        params.userMode = inspectionType.value;
        if (inspectionUser.value) {
            params.operateUser = inspectionUser.value;
        } else {
            ElMessage({
                type: "error",
                message: `请选择${params.userMode}`,
            });
            return;
        }
    }
    if (adjustType.value == "计划巡检时间") {
        params.inspPlanDate = moment(adjustTime.value).format("YYYY-MM-DD");
        params.status = "";
        params.userMode = "";
        params.operateUser = "";
    }
    if (adjustType.value == "任务状态") {
        params.inspPlanDate = "";
        params.status = adjustStatus.value;
        params.userMode = "";
        params.operateUser = "";
    }
    const res = await schedulingHttp.inspTaskAdjustTask(params);
    if (res.data.code == 200) {
        ElMessage({
            type: "success",
            message: "调整成功",
        });
        search();
        adjustVisible.value = false;
    } else {
        ElMessage({
            type: "error",
            message: "调整失败",
        });
    }
};
const activeName = ref("");

const handleClick = (name) => { };
const activeEq = ref({});
const currentTask = ref({});
// 填报
const reportTaskDataList = ref([]);
const reportTaskVisible = ref(false);
const reportTask = async (row) => {
    reportTaskVisible.value = true;
    currentTask.value = row;
    const res = await schedulingHttp.inspTaskQueryItems(row);
    if (res.data.code == "200") {
        console.log(res.data.data, "res.data.data");
        reportTaskDataList.value = res.data.data;
        activeName.value = res.data.data[0].id;
        activeEq.value = res.data.data[0];
        reportTaskDataList.value.forEach(async (item) => {
            item.fileList = [];
            if (item.imageIds !== "" && item.imageIds !== null) {
                const rsp = await schedulingHttp.fileInfoGetByIds(
                    item.imageIds
                );
                item.fileUrlList = rsp.data.data;
                item.fileList = rsp.data.data;
            }
            console.log(item.fileUrlList, "item.fileUrlList");
        });
    }
};
const uploadList = ref([]);
const fileList = ref([]);

const dialogImageUrl = ref("");
const dialogVisible = ref(false);

const handleRemove = (uploadFile, index) => {
    console.log(uploadFile, index);
    reportTaskDataList.value[index].fileList.forEach((m, n) => {
        if (uploadFile.id == m.id) {
            reportTaskDataList.value[index].fileList.splice(n, 1);
        }
    });
    console.log(reportTaskDataList.value[index].fileList);
};

const handlePictureCardPreview = (uploadFile) => {
    dialogImageUrl.value = uploadFile.url;
    dialogVisible.value = true;
};
const uploadImgCount = ref(0);
const httpRequest = (params, index) => {
    console.log(params, index, "httpRequest");
    uploadImgCount.value++;
    schedulingHttp.fileInfoUpload(params).then((res) => {
        if (res.data.code == 200) {
            console.log(res.data, "1111111");
            reportTaskDataList.value[index].fileList.push({
                fileName: res.data.data.fileName,
                url: res.data.data.url,
                id: res.data.data.id,
            });
            uploadImgCount.value--;
            ElMessage({
                type: "success",
                message: "上传成功",
            });
        }
    });
};
const reportTaskConfirm = async () => {
    if (uploadImgCount.value > 0) {
        ElMessage({
            type: "error",
            message: "请等待图片上传成功",
        });
        return;
    }
    let msgReportNoFinish = 0;
    let msgReportNoFinishList = [];
    reportTaskDataList.value.forEach((item) => {
        item.equipmentId = item.id;
        let imgids = [];
        if (item.fileList.length > 0) {
            item.fileList.forEach((m) => {
                imgids.push(m.id);
            });
            item.imageIds = imgids.join(",");
        } else {
            item.imageIds = "";
        }
        let itemsObj = Object.keys(item.items);
        itemsObj.forEach((t) => {
            if (item.items[t] == "") {
                msgReportNoFinish++;
                msgReportNoFinishList.push(
                    `${msgReportNoFinish}.【${item.facilityNumber}】中【${t}】未填写！\n`
                );
            }
        });
    });

    if (msgReportNoFinish > 0) {
        console.log("每天完");
        let msgText = msgReportNoFinishList.join("\n");
        ElMessage({
            message: msgText,
            type: "warning",
        });
        return;
    }
    let params = {
        id: currentTask.value.id,
        detailList: reportTaskDataList.value,
        inspContent: inspContent.value,
    };
    const res = await schedulingHttp.inspTaskReportTask(params);
    if (res.data.code == "200") {
        reportTaskVisible.value = false;
        ElMessage({
            type: "success",
            message: "提交成功",
        });
        search();
    } else {
        ElMessage({
            type: "error",
            message: "提交失败",
        });
    }
};
const saveTaskConfirm = async () => {
    reportTaskDataList.value.forEach((item) => {
        item.equipmentId = item.id;
        let imgids = [];
        if (item.fileList.length > 0) {
            item.fileList.forEach((m) => {
                imgids.push(m.id);
            });
            item.imageIds = imgids.join(",");
        } else {
            item.imageIds = "";
        }
    });
    let params = {
        id: currentTask.value.id,
        detailList: reportTaskDataList.value,
        inspContent: inspContent.value,
    };
    const res = await schedulingHttp.inspTaskSaveTask(params);
    if (res.data.code == "200") {
        reportTaskVisible.value = false;
        ElMessage({
            type: "success",
            message: "填报成功",
        });
        search();
    } else {
        ElMessage({
            type: "error",
            message: "填报失败",
        });
    }
};

let total = ref(0);
const handleSizeChange = (val) => {
    searchForm.pageSize = val;
    search();
};
const handleCurrentChange = (val) => {
    searchForm.pageNo = val;
    search();
};
const search = async () => {
    let params = {
        ...searchForm,
        startTime: searchForm.dateTime[0]
            ? moment(searchForm.dateTime[0]).format("YYYY-MM-DD")
            : "",
        endTime: searchForm.dateTime[1]
            ? moment(searchForm.dateTime[1]).format("YYYY-MM-DD")
            : "",
    };
    const res = await schedulingHttp.inspTaskQueryTask(params);
    if (res.data.code == 200) {
        tableData.value = res.data.data.records;
        total.value = res.data.data.total;
    }
};
const reset = () => {
    searchForm.depId = localTypeUnit.value;
    searchForm.inspectionLevel = "";
    searchForm.planName = "";
    searchForm.dateTime = [moment(), moment().add(7, "day")];
    searchForm.status = "";
    searchForm.pageNo = 1;
    searchForm.pageSize = 10;
    search();
};
const updatePlanVisible = ref(false);
const updateSearch = () => {
    updatePlanVisible.value = true;
};
const submitUpdatePlan = () => {
    let params = {
        depId: Number(searchForm.depId),
        startTime: updateTime.value[0]
            ? moment(updateTime.value[0]).format("YYYY-MM-DD")
            : "",
        endTime: updateTime.value[1]
            ? moment(updateTime.value[1]).format("YYYY-MM-DD")
            : "",
    };
    schedulingHttp.inspTaskUpdateTask(params).then((res) => {
        if (res.data.code == 200) {
            ElMessage({
                message: "更新成功",
                type: "success",
            });
            updatePlanVisible.value = false;
            search();
        } else {
            ElMessage({
                message: "更新失败！",
                type: "error",
            });
        }
    });
};
const recordTime = ref([]);
const recordList = ref([]);
const currentRowRecord = ref();
const optionRecord = async (row) => {
    recordListVisible.value = true;
    currentRowRecord.value = row;
    recordTime.value[0] = moment().format("YYYY-MM-DD");
    recordTime.value[1] = moment().add(1, "day").format("YYYY-MM-DD");
    searchRecord(currentRowRecord.value);
};
const recordPageNo = ref(1);
const recordPageSize = ref(10);

let totalRecord = ref(0);
const handleSizeChangeRecord = (val) => {
    recordPageSize.value = val;
    searchRecord(currentRowRecord.value);
};
const handleCurrentChangeRecord = (val) => {
    recordPageNo.value = val;
    searchRecord(currentRowRecord.value);
};
const searchRecord = async (row) => {
    let params = {
        businessId: row.id,
        operationType: "",
        businessType: "设备巡检",
        startTime:
            recordTime.value.length > 0
                ? moment(recordTime.value[0]).format("YYYY-MM-DD")
                : "",
        endTime:
            recordTime.value.length > 0
                ? moment(recordTime.value[1]).format("YYYY-MM-DD")
                : "",
        pageNo: recordPageNo.value,
        pageSize: recordPageSize.value,
    };
    const res = await schedulingHttp.operationRecordsQueryOperationRecords(
        params
    );
    if (res.data.code == 200) {
        recordList.value = res.data.data.records;
        totalRecord.value = res.data.data.total;
    }
};
const updateTask = () => { };
onMounted(() => {
    search();
});
</script>

<style scoped lang="less">
.filter {
    flex-wrap: wrap;
    display: flex;
    flex-direction: row;
    align-items: center;
    .filter-item {
        margin: 0 15px 15px 0px;
        display: flex;
        flex-direction: row;
        align-items: center;
        label {
            font-size: 14px;
            color: #333;
            display: inline-block;
            white-space: nowrap;
        }
    }
}
.reportLabel {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 60px;
    p {
        line-height: 1.5;
    }
}
:deep .el-dialog__body {
    padding: 20px !important;
}
:deep .el-tabs__item {
    height: 100px !important;
}
:deep .el-upload {
    width: 100px !important;
    height: 100px !important;
}
:deep .el-upload-list__item.is-ready {
    width: 100px !important;
    height: 100px !important;
}
:deep .el-upload-list__item.is-success {
    width: 100px !important;
    height: 100px !important;
}

.scopeBox {
    min-width: 130px;
}
.dialogTitle {
    line-height: 2;
    margin-bottom: 10px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}
.projectBox {
    padding: 0 20px;
    p {
        font-size: 16px;
        margin-bottom: 10px;
    }
    .urlBox {
        // display: flex;
        // flex-direction: row;
        margin-top: 30px;
    }
    ul li {
        line-height: 1.5;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}
</style>